/*
package com.example.controller;

import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

*/
/**
 * Author by admin, Email xx@xx.com, Date on 2020/5/29.
 * PS: Not easy to write code, please indicate.
 *//*

@RestController
public class SearchController {
    @Autowired
    //自定义名字。
    @Qualifier("restHighLevelClient")
    private RestHighLevelClient client;
    @GetMapping("/search/{keyword}")
    public List<Map<String,Object>> searchPgae(@PathVariable("keyword") String keyword,
                                               @RequestParam(name = "pagenum" ,defaultValue = "1")int pagenum,
                                               @RequestParam(name = "pageSize" ,defaultValue = "5")int pageSize) throws IOException {
        if (pagenum<=1){
            pagenum=1;
        }

        SearchRequest searchRequest = new SearchRequest("question_index");
        SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
        //分页
        searchSourceBuilder.from(pagenum);
        searchSourceBuilder.size(pageSize);
        //构造条件精准匹配
        searchSourceBuilder.query(QueryBuilders.matchQuery("title", keyword));
        searchSourceBuilder.timeout(new TimeValue(60, TimeUnit.SECONDS));
        //分页

        //执行搜索
        searchRequest.source(searchSourceBuilder);
        SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
        //解析结果
        ArrayList<Map<String,Object>> list = new ArrayList<>();
        for (SearchHit hit : searchResponse.getHits().getHits()) {
            System.out.println(hit.getSourceAsMap()+"111111");
            list.add(hit.getSourceAsMap());
        }
        return list;
    }

}
*/
